/*
 * Licensed to the 南京汇海交通科技有限公司
 *
 * Copyright (c) 2025.
 * All rights reserved.
 *
 * 本软件属南京汇海交通科技有限公司所有，在未获得南京汇海交通科技有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.cje.basic.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chframework.common.exception.DaoException;
import com.chframework.common.thread.wrapper.BenchmarksFuture;
import com.chframework.mybatis.CommonDAO;
import com.cje.basic.dao.mapper.DictTypeDOMapper;
import com.cje.basic.dataobject.DictTypeDO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class DictTypeDAO extends CommonDAO<DictTypeDOMapper, DictTypeDO> {

    /**
     * 分页查询字典数据
     */
    public BenchmarksFuture<IPage<DictTypeDO>> pageDictType(DictTypeDO dictTypeDO, long current, long size) {
        return BenchmarksFuture.supplyAsync(() -> {
            IPage<DictTypeDO> page = new Page<>(current, size);
            return super.baseMapper.pageDictType(page, dictTypeDO);
        }).exceptionally(throwable -> {
            throw new DaoException(throwable.getCause());
        });
    }

    /**
     * 查询指定字典类型的字典配置项数据
     */
    public BenchmarksFuture<DictTypeDO> getDictType(DictTypeDO dictTypeDO) {
        return BenchmarksFuture.supplyAsync(() ->
                this.selectOne(Wrappers.<DictTypeDO>lambdaQuery()
                        .eq(DictTypeDO::getStatus, 0)
                        .eq(DictTypeDO::getDictType, dictTypeDO.getDictType()))
        ).exceptionally(throwable -> {
            throw new DaoException(throwable.getCause());
        });
    }

    /**
     * 新增字典数据
     */
    public BenchmarksFuture<Boolean> postDictType(DictTypeDO dictTypeDO) {
        return BenchmarksFuture.supplyAsync(() ->
                super.save(dictTypeDO)
        ).exceptionally(throwable -> {
            throw new DaoException(throwable.getCause());
        });
    }

    /**
     * 删除指定的字典类型
     */
    public BenchmarksFuture<Boolean> deleteDictType(DictTypeDO dictTypeDO) {
        return BenchmarksFuture.supplyAsync(() ->
                super.removeById(dictTypeDO)
        ).exceptionally(throwable -> {
            throw new DaoException(throwable.getCause());
        });
    }

    /**
     * 修改字典类型
     */
    public BenchmarksFuture<Boolean> putDictType(DictTypeDO dictTypeDO) {
        return BenchmarksFuture.supplyAsync(() ->
                super.updateById(dictTypeDO)
        ).exceptionally(throwable -> {
            throw new DaoException(throwable.getCause());
        });
    }

}
